var log = console.log;

var exp = module.exports;

var num = 0;

var cardPool = ['D1', 'C2', 'A2', 'D3', 'D4', 'C4', 'B4', 'A4', 'C5', 'A5', 'D6', 'C6', 'B6', 'A6', 'D7', 'C7', 'B7', 'A7', 'D8', 'C8', 'B8', 'A8', 'C9', 'A9', 'D10', 'C10', 'B10', 'A10', 'C11', 'A11', 'C12', 'A12'];

function next(rid) {
    var ret, num;
    num = 1 + parseInt(Math.random() * 120);
    switch (true) {
        case num <= 3:
            ret = 1;
            break;
        case num <= 7:
            ret = 2;
            break;
        case num <= 13:
            ret = 3;
            break;
        case num <= 25:
            ret = 4;
            break;
        case num <= 49:
            ret = 5;
            break;
        case num <= 73:
            ret = 6;
            break;
        case num <= 97:
            ret = 7;
            break;
        default:
            ret = 8;
    }
    var odds = getOdds(ret);
    return { ret, odds };
}

function getOdds(num) {
    var obj = {
        1: 40,
        2: 30,
        3: 20,
        4: 10,
        5: 5,
        6: 5,
        7: 5,
        8: 5
    };
    var odds = {};
    for (var k in obj) {
        if (parseInt(k) === parseInt(num)) {
            odds[k] = obj[k];
        }
        else {
            odds[k] = -1;
        }
    }
    return odds;
}

// 如果顶替，就一直顶替
function replaceNum(reNum) {
    if (!isNaN(reNum) && reNum <= 8 && reNum > 0) {
        num = reNum;
        return true;
    }
}


exp.next = next;
exp.replaceNum = replaceNum;
